/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024.
 * Description: header for rtos_pfn_valid support
 * Author: heyuqiang
 * Create: 2024-1-22
 */

#ifndef _RTOS_PFN_VALID_H_
#define _RTOS_PFN_VALID_H_

#ifdef CONFIG_RTOS_PFN_VALID

#include <linux/memblock.h>

#if defined(CONFIG_ARM) && defined(CONFIG_HAVE_ARCH_PFN_VALID)
static inline int rtos_pfn_valid(unsigned long pfn)
{
	phys_addr_t addr = __pfn_to_phys(pfn);
	if (__phys_to_pfn(addr) != pfn)
		return 0;

	return memblock_is_map_memory(__pfn_to_phys(pfn));
}
#else
static inline int rtos_pfn_valid(unsigned long pfn)
{
	return pfn_valid(pfn);
}
#endif

#endif /* CONFIG_RTOS_PFN_VALID */
#endif
